package pro.softzhang.algo.lc100;

import pro.softzhang.algo.flag.knowledge.KBitManipulation;
import pro.softzhang.algo.flag.theme.TMath;

/**
 *
 */
@KBitManipulation
@TMath
public class LC137_SingleNumberII {
    public static void main(String[] args) {
        int[] nums = new int[]{2,2,3,2};
        System.out.println(new Solution().singleNumber(nums));
    }

    static
    class Solution {
        public int singleNumber(int[] nums) {
            int[] arr = new int[32];
            for (int num : nums) {
                for (int i = 0; i <= 31; i++) {
                    arr[i] += num >> (31 - i) & 1;
                }
            }
            int s = 0;
            for (int i = 0; i <= 31; i++) {
                s = (s << 1) + (arr[i] % 3);
            }
            return s;
        }
    }
}